#!/bin/sh
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.

. $LKP_SRC/lib/job.sh
load_job_vars GIT_SERVER SCHED_HOST

export server_ip=$SCHED_HOST

git_ci()
{
	# use $GIT_SERVER to direct git remote repo from gitee.com to our own git remote repo(by container git-daemon),
	# to make sure can use the latest code.
	if [ -n "$GIT_SERVER" ]; then
		cat >> /etc/gitconfig <<-EOF
		[url "git://$GIT_SERVER/gitee.com"]
			insteadOf=https://gitee.com
		EOF
	fi

	git clone --depth=1 https://gitee.com/openeuler/compass-ci.git /c/compass-ci || \
	git clone --depth=1 http://gitee.com/openeuler/compass-ci.git /c/compass-ci || \
	return 1

	(
		cd /c/compass-ci
		while :
		do
			git pull
			sleep 1h
		done
	)&
}

deploy()
{
	cd /c/compass-ci/sparrow && ./install-client
}

git_ci || exit 1
deploy
